/-app ...
/-app/ko
/-app/koBindingHandlers
$element.ts
register.ts
/-app/koBindings
PageModel.ts
main.css
start.ts
/-docs
/-docs/types
DocHost.ts
/-files
FileTree.css
FileTree.ts
/-imports
/-persistence
/-typings
codemirror.d.ts
knockout.d.ts
websql.d.ts
errors.js
functions.ts
index.html
try.js
 
1
module teapo.app {
2
  
3
  export class TopLayout {
4
​
5
    private _drive: persistence.Drive = null;
6
    private _fileTree: teapo.files.FileTree = null;
7
    private _docHost: docs.DocHost = null;
8
​
9
    mainContentHost = ko.observable<HTMLElement>(null);
10
    fileTreeHost = ko.observable<HTMLElement>(null);
11
​
12
    constructor() {
13
    }
14
​
15
    loadFromDOM() {
16
      var fileTree = new teapo.files.FileTree(this.fileTreeHost());
17
​
18
      var uniqueKey = this._getUniqueKey();
19
      var domTimestamp = 0;
20
​
21
      persistence.mountDrive(
22
        fileTree,
23
        uniqueKey,
24
        domTimestamp,
25
        <any>teapo.persistence,
26
        mountedDrive => {
27
​
28
          var docHost = new docs.DocHost(this.mainContentHost(), mountedDrive);
29
          
30
          this._fileTree = fileTree;
31
          this._docHost = docHost;
32
          this._drive = mountedDrive;
33
          
34
          this._fileTree.selectedFile.subscribe(newSelectedFile => this._docHost.show(newSelectedFile));
35
​
36
        });
37
    }
38
  
39
    addClick() {
40
      var typedFilename = prompt('Create file:', this._fileTree.selectedFile() || '/' );
41
      if (!typedFilename)
42
        return;
43
      
44
      var newFile = files.normalizePath(typedFilename);
45
      
46
      if (this._drive.read(newFile) === null) {
47
        this._drive.write(newFile, '');
48
        this._docHost.add(newFile);
49
      }
50
      
51
      this._fileTree.selectedFile(newFile);
52
    }
53
  
54
    deleteClick() {
55
      
56
      var removeFile = this._fileTree.selectedFile();
57
      if (!removeFile)
58
        return;
59
      
60
      if (!confirm('Remove file\n  ' + removeFile + '  ?'))
61
      
62
              this._drive.write(removeFile, null);
63
      this._docHost.remove(removeFile);
64
    }
65
  
66
    private _getUniqueKey() {
67
      var key = window.location.pathname;
68
​
69
      key = key.split('?')[0];
70
      key = key.split('#')[0];
71
​
72
      key = key.toLowerCase();
73
​
74
      var ignoreSuffix = '/index.html';
75
​
76
      if (key.length > ignoreSuffix.length && key.slice(key.length - ignoreSuffix.length) === ignoreSuffix)
77
        key = key.slice(0, key.length - ignoreSuffix.length);
78
​
79
      return key;
80
    }
81
​
82
  }
83
  
84
}
83:1